<?php
class Controller extends CController
{
    public function sendMail($template, $subject, $toEmail, $params)
    {
        $message = new YiiMailMessage;
        $message->view = $template;
        $message->setBody($params, 'text/html');
        $message->subject = $subject;
        $message->addTo($toEmail);
        $message->from = Yii::app()->params['admin.email'];
        Yii::app()->mail->send($message);
    }

    public function addPlayer()
    {

    }

    public function addUser()
    {

    }

    public function addCoach()
    {

    }

    public function addManager()
    {
        $user = new User();
        $user->username = $_POST['email'];
        $user->password = $_POST['password'];
        $user->save();

        $person = new Person;
        $person->firstname = $_POST['firstName'];
        $person->lastname = $_POST['lastName'];
        $person->sex = $_POST['sex'];
        $person->birthdate = $_POST['birthday'];
        $person->citizenship_id = $_POST['citizenship'];
        $person->residence_id = $_POST['residence'];

        $person->user_id = $user->id;

        $person->save();

        $manager = new Manager;
        $manager->person_id = $person->id;
        $manager->save();
    }

    public function getLanguages()
    {
        return array("English", "German", "French", "Spanish", "Danish", "Slovenian",
            "Croatian", "Russian", "Hungarian", "Romanian", "Portuguese", "Serbian",
            "Swedish", "Macedonian ", "Polish", "Ukranian ", "Bosnian", "Norwegian",
            "Belarusian", "Greek", "Hebrew", "Slovak", "Turkish", "Italian", "Dutch",
            "Icelandic", "Czech", "Estonian", "Bulgarian", "Finnish", "Latvian", "Lithuanian",
            "Albanian", "Korean ", "Arabic ", "Chinese", "Japanese", "Hindi  ", "Indonesian");
    }

    public function getCountries()
    {
        return Country::model()->findAll();
    }
}